package com.hanbang.maige.widget.drawable;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

import com.hanbang.maige.R;


/**
 * 作者　　: 李坤
 * 创建时间:2016/9/28　16:52
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class PingLunDrawable extends Drawable {
    Paint paint;
    private int shanjiaSize = 0;
    private int circleRadius = 0;

    public PingLunDrawable(Context context) {
        shanjiaSize = context.getResources().getDimensionPixelSize(R.dimen.dp_8);
        circleRadius = context.getResources().getDimensionPixelSize(R.dimen.dp_4);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setColor(context.getResources().getColor(R.color.gray_f0));
        paint.setStyle(Paint.Style.FILL);

    }

    @Override
    public void draw(Canvas canvas) {
        Path path = new Path();
        Rect rect = getBounds();
//        path.moveTo(circleRadius, rect.bottom);
//        RectF rectFLeftBottom = new RectF(0, rect.bottom - circleRadius * 2, circleRadius * 2, rect.bottom);
//        path.addArc(rectFLeftBottom, 90f, 90f);
//        path.lineTo(0, shanjiaSize);
//
//        RectF rectFLeftTop = new RectF(0, shanjiaSize, circleRadius * 2, circleRadius * 2 + shanjiaSize);
//        path.addArc(rectFLeftTop, 180f, 90f);
//
//        path.lineTo(shanjiaSize * 2, shanjiaSize);
//        path.lineTo(shanjiaSize * 2 + shanjiaSize * 1.5f / 2.0f, 0);
//        path.lineTo(shanjiaSize * 3.5f, shanjiaSize);
//        path.lineTo(rect.right - circleRadius, shanjiaSize);
//
//        RectF rectFRightTop = new RectF(rect.right - circleRadius * 2, shanjiaSize, rect.right, shanjiaSize + circleRadius * 2);
//        path.addArc(rectFRightTop, 270f, 90f);
//
//        path.lineTo(rect.right, rect.bottom - circleRadius * 2);
//
//        RectF rectFRightBottom = new RectF(rect.right - circleRadius * 2, rect.bottom - circleRadius * 2, rect.right, rect.bottom);
//        path.addArc(rectFRightBottom, 0f, 90f);
        RectF roundRect = new RectF(0, shanjiaSize, rect.right, rect.bottom);
        canvas.drawRoundRect(roundRect, circleRadius, circleRadius, paint);


        path.moveTo(shanjiaSize, shanjiaSize);
        path.lineTo(shanjiaSize + shanjiaSize * 1.5f / 2.0f, 0);
        path.lineTo(shanjiaSize * 2.5f, shanjiaSize);
        canvas.drawPath(path, paint);
    }

    @Override
    public void setAlpha(int alpha) {

    }

    @Override
    public void setColorFilter(ColorFilter colorFilter) {

    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}
